package com.rykj.ruiyan_ptz.wiget

import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import androidx.annotation.RequiresApi
import com.rykj.common.utils.RYLogger
import com.rykj.ruiyan_ptz.Define
import com.rykj.ruiyan_ptz.R
import com.rykj.ruiyan_ptz.control.UDPManager
import kotlinx.android.synthetic.main.main_status.view.*

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
class MainStatus
@JvmOverloads
constructor(context: Context, attrs: AttributeSet, defStyle: Int = 0, defStyleRes: Int = 0) :
    RelativeLayout(context, attrs, defStyle, defStyleRes) {
    init {
        View.inflate(context, R.layout.main_status, this)
        init()
    }

    private val define: Define = Define();
    private fun init() {
        initClickListener()
    }

    private fun initClickListener() {
        //todo 以下方法都需要调用udp
        stop_track.setOnClickListener {
            UDPManager.get().PtzMove(define.ptzType_Yaw, define.PTZ_UP, 1, 1)
            RYLogger.i("MainStatus", "停止追踪")
        }
        start_autopilot.setOnClickListener {
            RYLogger.i("MainStatus", "开启自动巡航")
        }
        upload.setOnClickListener {
            RYLogger.i("MainStatus", "单模板匹配")
        }
        zoomIn.setOnClickListener {
            RYLogger.i("MainStatus", "放大")
            UDPManager.get().ZoomAction(1,define.ZOOM_ENLARGE)
        }
        zoomOut.setOnClickListener {
            RYLogger.i("MainStatus", "缩小")
            UDPManager.get().ZoomAction(1,define.ZOOM_NARROW)
        }
        //todo 以上方法都需要调用udp
        screenshot.setOnClickListener {
            RYLogger.i("MainStatus", "截图")
        }
        startRecord.setOnClickListener {
            RYLogger.i("MainStatus", "开始保存视频")
        }
        stopRecord.setOnClickListener {
            RYLogger.i("MainStatus", "停止保存视频")
        }
    }

    fun setText(status: String) {
        main_status_text.text = status
    }
}